/**
 * 增加会员页面类
 * 业务层级：表示层
 * 功能说明：提供新会员注册的用户界面，包括会员信息输入表单和提交功能
 * 架构关系：遵循四层架构设计，调用业务层服务添加会员，为用户提供会员注册功能
 */
#ifndef ADDMEMBERPAGE_H
#define ADDMEMBERPAGE_H

#include <QWidget>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QLabel>
#include <QPushButton>
#include <QLineEdit>
#include <QGroupBox>
#include <QMessageBox>
#include <QRegularExpressionValidator>
#include "../services/memberservice.h"
#include "../database/database.h"

class AddMemberPage : public QWidget
{
    Q_OBJECT

public:
    explicit AddMemberPage(Database *db, QWidget *parent = nullptr);
    ~AddMemberPage();

private slots:
    void onSubmitClicked();
    void onClearClicked();
    void onNameTextChanged();
    void onPhoneTextChanged();

private:
    void initUI();
    void setupInputForm();
    void setupButtonArea();
    void applyGreenThemeStyles();
    
    void clearForm();
    bool validateInput();
    void showSuccessMessage(const QString &message);
    void showErrorMessage(const QString &message);

    // 数据服务
    MemberService *m_memberService;
    Database *m_db;

    // 主布局组件
    QVBoxLayout *m_mainLayout;
    
    // 输入表单区域
    QGroupBox *m_inputGroup;
    QGridLayout *m_inputLayout;
    
    // 输入控件
    QLabel *m_nameLabel;
    QLineEdit *m_nameEdit;
    QLabel *m_phoneLabel;
    QLineEdit *m_phoneEdit;
    QLabel *m_tipLabel;
    
    // 按钮区域
    QWidget *m_buttonArea;
    QHBoxLayout *m_buttonLayout;
    QPushButton *m_submitBtn;
    QPushButton *m_clearBtn;
    
    // 验证器
    QRegularExpressionValidator *m_phoneValidator;
};

#endif // ADDMEMBERPAGE_H